/*
 Copyright (C) 2013 Yuyao Liang

 This source code is release under the BSD License.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
 

 */
package com.googlecode.stereoplot;

import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;

import org.jfree.chart.plot.dial.DialPlot;
import org.jfree.chart.plot.dial.StandardDialFrame;

/**
 * @author lianyuy
 * 
 */
public class StereoPlotDialFrame extends StandardDialFrame {

	private static final long serialVersionUID = -813995577800984580L;

	public StereoPlotDialFrame() {
	}

	/**
	 * Draws the frame. This method is called by the {@link DialPlot} class, you
	 * shouldn't need to call it directly.
	 * 
	 * @param g2
	 *            the graphics target (<code>null</code> not permitted).
	 * @param plot
	 *            the plot (<code>null</code> not permitted).
	 * @param frame
	 *            the frame (<code>null</code> not permitted).
	 * @param view
	 *            the view (<code>null</code> not permitted).
	 */
	@Override
	public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
			Rectangle2D view) {

		Shape window = getWindow(frame);

		Rectangle2D f = DialPlot.rectangleByRadius(frame,
				this.getRadius() + 0.02, this.getRadius() + 0.02);
		Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(),
				f.getHeight());

		Area area = new Area(e);
		Area area2 = new Area(window);
		area.subtract(area2);
		g2.setPaint(this.getBackgroundPaint());
		g2.fill(area);

		g2.setStroke(this.getStroke());
		g2.setPaint(this.getForegroundPaint());
		g2.draw(window);
		g2.draw(e);
	}
}
